package com.zzyl.nursing.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.zzyl.nursing.domain.Reservation;
import com.zzyl.nursing.mapper.MemberReservationMapper;
import com.zzyl.nursing.service.IMemberReservationService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.time.Instant;
import java.time.LocalDateTime;
import java.time.ZoneId;
import java.util.List;

@Service
public class MemberReservationServiceImpl extends ServiceImpl<MemberReservationMapper, Reservation> implements IMemberReservationService {

    @Autowired
    private MemberReservationMapper memberReservationMapper;
    @Override
    public Integer getCancelledReservationCount() {
        Long count = lambdaQuery().eq(Reservation::getStatus, 2)
                .count();
        return Integer.parseInt(count.toString());
    }
    /**
     * 取消预约
     * @param id
     */
    @Override
    public void cancelReservation(Long id) {
        Reservation reservation = this.getById(id);
        reservation.setStatus(2);
        this.updateById(reservation);
    }

    /**
     * 分页查询预约信息
     * @param status
     * @return
     */
    @Override
    public List<Reservation> selectByPage( Integer status) {

        //根据分页条件查询预约信息
        Reservation reservation = new Reservation();
        reservation.setStatus( status);
        List<Reservation> reservations = memberReservationMapper.selectReservationList(reservation);
        return reservations;
    }

    /**
     * 添加预约信息
     * @param reservation
     */
    @Override
    public void add(Reservation reservation) {
        reservation.setStatus(1);
        reservation.setType(0);
        this.save( reservation);
    }

    /**
     * 根据时间查询预约信息
     * @param time
     * @return
     */
    @Override
    public Integer countByTime(Long time) {
       //将毫秒值转换为LocalDateTime
        LocalDateTime dateTime = LocalDateTime.ofInstant(
                Instant.ofEpochMilli(time),
                ZoneId.systemDefault()
        );
       return null;
    }
}
